import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/user_list',
    children: [
      {
        path: 'user_list',
        name: 'userList',
        component: () => import('@/views/user_list/index'),
        meta: {
          title: '用户列表',
          breadcrumb: true
        }
      },
      {
        path: 'role_list',
        name: 'perList',
        component: () => import('@/views/per_list/index'),
        meta: {
          title: '权限列表',
          breadcrumb: true
        }
      },
      {
        path: 'author_list',
        name: 'roleList',
        component: () => import('@/views/role_list/index'),
        meta: {
          title: '角色列表',
          breadcrumb: true
        }
      },
      {
        path: 'group_list',
        name: 'cateList',
        component: () => import('@/views/cate_list/index'),
        meta: {
          title: '分类列表',
          breadcrumb: true
        }
      },
      {
        path: 'attr_list',
        name: 'attrList',
        component: () => import('@/views/attr_list/index'),
        meta: {
          title: '属性列表',
          breadcrumb: true
        }
      },
      {
        path: 'product_list',
        name: 'goodsList',
        component: () => import('@/views/goods_list/index'),
        meta: {
          title: '商品列表',
          breadcrumb: true
        }
      },
      {
        path: 'addGood',
        name: 'addGood',
        component: () => import('@/views/goods_list/children/addGood.vue'),
        meta: {
          title: '增加商品',
          breadcrumb: true
        }
      },
      {
        path: 'order_list',
        name: 'OrderList',
        component: () => import('@/views/order_list/index'),
        meta: {
          title: '订单列表',
          breadcrumb: true
        }
      },
      {
        path: 'count_list',
        name: 'countList',
        component: () => import('@/views/count_list/index'),
        meta: {
          title: '统计列表',
          breadcrumb: true
        }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
